package com.xx.jicheng.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yihang.common.spring.Inject;

import com.xx.jicheng.entity.City;
import com.xx.jicheng.service.CityService;
import com.xx.jicheng.service.ConfigService;

@Controller
public class AdminConfigAddressController {

	@Autowired
	private CityService cityService;

	@RequestMapping("/admin/config/address")
	public void address() {

	}

	/**
	 * 1) 为了能够在@Cacheable的条件里使用SpringEL, 需要实现方法参数注入
	 * <br/>
	 * 2) ConfigService不应当作为key，否则还得序列化
	 * <br/>
	 * @see org.yihang.common.spring.InjectArgumentResolver
	 */
	@RequestMapping("/admin/config/address/find")
	@Cacheable(cacheNames = "city.cache", condition = "#configService.isCacheEnabled('city.cache.enable')", key = "#id")
	@ResponseBody
	public List<City> findByPid(@RequestParam(defaultValue = "100000") Integer id,
			@Inject("configService") ConfigService configService) {
		return cityService.findByPid(id);
	}

}
